﻿using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using SharpAnalyzer.Utilities;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;

namespace SharpAnalyzer.Analyzers
{
    internal sealed class MethodLocalVariablesAnalyzer : CSharpSyntaxWalker
    {
        private int numLocalVariables;

        public MethodLocalVariablesAnalyzer()
          : base(SyntaxWalkerDepth.Node)
        {
        }

        public int Calculate(SyntaxNode memberNode)
        {
            Verify.NotNull(() => memberNode);

            if (memberNode != null)
                Visit(memberNode);
            return numLocalVariables;
        }

        public override void VisitVariableDeclaration(VariableDeclarationSyntax node)
        {
            base.VisitVariableDeclaration(node);
            checked { ++numLocalVariables; }
        }
    }
}
